var express = require('express');
var router = express.Router();

let jwtUtils = require('../utils/jwtUtils')
const article = require('../middleware/article_mid')
const mail = require('../utils/mailUtil')
//加载首页页面
router.get('/', function (req, res, next) {
    // res.render('index1', {host:req.hots });
    //   res.send({hots:req.hots})
});
router.get('/getHot', function (req, resp, next) {
    // res.render('index1', {host:req.hots });
    article.getHot(req, resp, next);
});
router.get('/searchCent', function (req, resp, next) {
    // res.render('index1', {host:req.hots });
    //   article.(req,resp,next);
    article.searchCent(req, resp)
});

router.post('/setEM', function (req, resp, next) {
    console.log('11111')
    // res.render('index1', {host:req.hots });
    //   let u_id = localStorage.getItem("u_id");
    let body = req.body
    let emil = body.emil;
    let title = body.title;
    let content = body.content;
    let htmlCen = body.htmlCen;
    let call = body.call;
    let u_id = body.u_id;
    let token = jwtUtils.sign({u_id: u_id, emil: emil}, global.globalKey, 36000)
    let urldata = "http://localhost:3000/verify?token=" + token
    mail.emailTo(emil, "洪吉林博客验证", "请您点击进行邮箱绑定验证", urldata, function (a) {
        resp.send(a)
    })
});
let User = require('../middleware/user_mid')
router.get('/verify', async function (req, resp, next) {
    User.bindUserEmils(req, resp)


})

module.exports = router;
